<template>
    <div class='detail-container page-container'>
        <el-form id="form" :model='orderForm' :rules='rules' ref='orderForm' label-width='110px'>
            <div class='create-edit-post'>
                <el-row>
                    <el-col :span='12'>
                        <el-form-item prop='orderNum' label='订单编号'>
                            <el-input v-model='orderForm.orderNum' class='normal-input'></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span='12'>
                        <el-form-item prop='view1' label='外商国别'>
                            <el-select
                                    v-model='orderForm.view1'
                                    :placeholder='orderForm.show1'
                                    filterable
                                    clearable
                                    @change='changeCountries()'
                                    class='normal-input'
                            >
                                <el-option
                                        v-for='item in countries'
                                        :key='item.id'
                                        :label='item.name'
                                        :value='item.id'
                                ></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span='12'>
                        <el-form-item prop='orderTime' label='订单日期'>
                            <el-date-picker
                                    type='date'
                                    placeholder='选择订单日期'
                                    v-model='orderForm.orderTime'
                                    format='yyyy-MM-dd'
                                    value-format='yyyy-MM-dd'
                                    class='normal-input'
                            ></el-date-picker>
                        </el-form-item>
                    </el-col>
                    <el-col :span='12'>
                        <el-form-item prop='deliveryTime' label='交货日期'>
                            <el-date-picker
                                    type='date'
                                    placeholder='选择交货日期'
                                    v-model='orderForm.deliveryTime'
                                    format='yyyy-MM-dd'
                                    value-format='yyyy-MM-dd'
                                    class='normal-input'
                            ></el-date-picker>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span='12'>
                        <el-form-item prop='view4' label='抵运国'>
                            <el-select
                                    v-model='orderForm.view4'
                                    :placeholder='orderForm.show4'
                                    @change='change(4)'
                                    filterable
                                    clearable
                                    class='normal-input'
                            >
                                <el-option
                                        v-for='item in endCountry'
                                        :key='item.id'
                                        :label='item.name'
                                        :value='item.id'
                                ></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span='12'>
                        <el-form-item prop='view10' label='订单币种'>
                            <el-select
                                    v-model='orderForm.view10'
                                    :placeholder='orderForm.show10'
                                    @change='change(10)'
                                    filterable
                                    clearable
                                    class='normal-input'
                            >
                                <el-option v-for='item in ddbz' :key='item.id' :label='item.name'
                                           :value='item.id'></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span='12'>
                        <el-form-item label='报关地海关'>
                            <el-select
                                    v-model='orderForm.view2'
                                    :placeholder='orderForm.show2'
                                    @change='change(2)'
                                    filterable
                                    clearable
                                    class='normal-input'
                            >
                                <el-option
                                        v-for='item in customs'
                                        :key='item.id'
                                        :label='item.name'
                                        :value='item.id'
                                ></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>

                    <el-col :span='12'>
                        <el-form-item label='起运港'>
                            <el-select
                                    v-model='orderForm.view3'
                                    :placeholder='orderForm.show3'
                                    @change='change(3)'
                                    filterable
                                    clearable
                                    class='normal-input'
                            >
                                <el-option
                                        v-for='item in startPort'
                                        :key='item.id'
                                        :label='item.name'
                                        :value='item.id'
                                ></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>

                    <el-col :span='12'>
                        <el-form-item label='目的港'>
                            <el-select
                                    v-model='orderForm.view5'
                                    :placeholder='orderForm.show5'
                                    @change='change(5)'
                                    filterable
                                    clearable
                                    class='normal-input'
                            >
                                <el-option
                                        v-for='item in endPort'
                                        :key='item.id'
                                        :label='item.name'
                                        :value='item.id'
                                ></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span='12'>
                        <el-form-item label='收汇方式'>
                            <el-select
                                    v-model='orderForm.view11'
                                    :placeholder='orderForm.show11'
                                    @change='change(11)'
                                    filterable
                                    clearable
                                    class='normal-input'
                            >
                                <el-option v-for='item in shfs' :key='item.id' :label='item.name'
                                           :value='item.id'></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span='12'>
                        <el-form-item label='贸易方式'>
                            <el-select
                                    v-model='orderForm.view6'
                                    :placeholder='orderForm.show6'
                                    @change='change(6)'
                                    filterable
                                    clearable
                                    class='normal-input'
                            >
                                <el-option v-for='item in myfs' :key='item.id' :label='item.name'
                                           :value='item.id'></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span='12'>
                        <el-form-item label='价格条款'>
                            <el-select
                                    v-model='orderForm.view7'
                                    :placeholder='orderForm.show7'
                                    @change='change(7)'
                                    filterable
                                    clearable
                                    class='normal-input'
                            >
                                <el-option v-for='item in jgtk' :key='item.id' :label='item.name'
                                           :value='item.id'></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span='12'>
                        <el-form-item label='包装种类'>
                            <el-select
                                    v-model='orderForm.view8'
                                    :placeholder='orderForm.show8'
                                    @change='change(8)'
                                    filterable
                                    clearable
                                    class='normal-input'
                            >
                                <el-option v-for='item in bzfs' :key='item.id' :label='item.name'
                                           :value='item.id'></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span='12'>
                        <el-form-item label='运输方式'>
                            <el-select
                                    v-model='orderForm.view9'
                                    :placeholder='orderForm.show9'
                                    @change='change(9)'
                                    filterable
                                    clearable
                                    class='normal-input'
                            >
                                <el-option v-for='item in ysfs' :key='item.id' :label='item.name'
                                           :value='item.id'></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>

                <el-row>
                    <el-col :span='12'>
                        <el-form-item label='备注'>
                            <el-input
                                    type="textarea"
                                    v-model="orderForm.meno"
                                    :autosize="{ minRows: 3, maxRows: 5}"
                                    placeholder="请输入备注内容">
                            </el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span='12'>
                        <el-form-item label='关联报关单'>
                            <el-input
                                    type="textarea"
                                    v-model="orderForm.fb4"
                                    :autosize="{ minRows: 3, maxRows: 5}"
                                    placeholder="请输入关联报关单">
                            </el-input>
                            <!--<el-input v-model="orderForm.fb4" placeholder="请输入关联报关单"></el-input>-->
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <!-- <el-col :span='12'>
                      <el-form-item label='运输支付方式'>
                        <el-select
                          v-model='orderForm.view12'
                          :placeholder='orderForm.show12'
                          @change='change(12)'
                          disabled
                          filterable
                          clearable
                          class='normal-input'
                        >
                          <el-option
                            v-for='item in yszffs'
                            :key='item.id'
                            :label='item.name'
                            :value='item.id'
                          ></el-option>
                        </el-select>
                      </el-form-item>
                    </el-col>-->
                    <el-col :span='12'>
                        <el-form-item label='已投保中信保'>
                            <el-switch v-model='orderForm.isTop'></el-switch>
                        </el-form-item>
                    </el-col>
                 <!--   <el-col :span='12'>
                        <el-form-item style="float: right;" label='备货订单模式'>
                            <el-switch v-model="tmpModel" @change="getTmpModel"></el-switch>
                        </el-form-item>
                    </el-col>-->

                </el-row>
                <el-row class='goods-list'>
                    <el-col :span='24'>
                        <el-button size='small' type='primary' plain class='create-goods' style='float: left;' @click="handleCreateGoods('','')" icon='el-icon-plus'>新增商品</el-button>
                        <el-form-item label='订单商品列表' style="overflow: hidden;float: right;"></el-form-item>
                        <el-table :data='goodsList' border fit stripe style='width: 100%;'>
                            <el-table-column prop='id' align='center' label='id' width='0'
                                             v-if='false'></el-table-column>
                            <el-table-column prop='hsCode' align='center' label='海关商品编码'
                                             sortable></el-table-column>
                            <el-table-column prop='hsName' align='center' label='商品品名'
                                             sortable></el-table-column>
                            <el-table-column
                                    prop='specification'
                                    align='center'
                                    label='规格型号'
                                    sortable
                            ></el-table-column>
                            <el-table-column prop='isOwm' align='center' label='自有品牌'
                                             sortable></el-table-column>
                            <el-table-column prop='amount' align='center' label='订单数量'
                                             sortable></el-table-column>
                            <el-table-column prop='statisticUnits' align='center'
                                             label='统计单位'></el-table-column>
                            <el-table-column prop='unitPrice' align='center' label='成交单价'
                                             sortable></el-table-column>
                            <el-table-column prop='totalPrice' align='center' label='成交总价'
                                             sortable></el-table-column>
                            <el-table-column
                                    prop='originalGoodsPlace'
                                    align='center'
                                    label='境内货源地'
                                    sortable
                            ></el-table-column>
                            <el-table-column align='center' min-width="220" label='操作'>
                                <template slot-scope='scope'>
                                    <el-button
                                            size='small'
                                            type='primary'
                                            plain
                                            @click='handleCreateGoods(scope.$index, scope.row)'
                                    >修改
                                    </el-button>
                                    <el-button
                                            size='small'
                                            type='danger'
                                            plain
                                            @click='handleDeleteGoods(scope.$index)'
                                    >删除
                                    </el-button>
                                    <el-button size='small' type='success' plain @click='copyHandle(scope.row)'>复制</el-button>
                                </template>
                            </el-table-column>
                        </el-table>
                        <div class='pagination-container'>
                            <el-pagination
                                    background
                                    layout='total, prev, pager, next'
                                    :total='total'
                                    :page-count='count'
                                    :page-size='size'
                                    :current-page='pageCurrent'
                                    @current-change='handleCurrentChange'
                            ></el-pagination>
                        </div>
                    </el-col>
                </el-row>

                <el-row>
                    <el-col :span='24' class='submit-btn'>
                        <el-button class='create-goods' type='info'
                                   @click="tmpHandle">提交备货订单
                        </el-button>
                        <el-button
                                class='create-goods'
                                type='primary'
                                :disabled="ctrBtn1"
                                @click="submitForm('orderForm','1')"
                        >提交在手订单
                        </el-button>
                        <el-button
                                class='create-goods'
                                type='warning'
                                @click="submitForm('orderForm','2')"
                        >提交报关订单
                        </el-button>
                        <!--<el-button-->
                                <!--class='create-goods'-->
                                <!--type='danger'-->
                                <!--@click="tmpHandle2"-->
                        <!--&gt;提交中止订单-->
                        <!--</el-button>-->
                    </el-col>
                </el-row>
            </div>
        </el-form>
        <el-dialog title='新增商品' :visible.sync='goodsDialog' width='60%' center>
            <div style='width:80%; margin: auto;'>
                <el-form :model='goodsForm' :rules='rules' ref='goodsForm' label-width='110px'>
                    <el-row>
                        <el-col :span='24'>
                            <el-form-item prop='hsCode' label='海关商品品类'>
                                <el-autocomplete
                                        type='text'
                                        class='inline-input'
                                        v-model='goodsForm.hsCode'
                                        :fetch-suggestions='querySearchHSAsync'
                                        :trigger-on-focus='false'
                                        @select='handleHSSelect'
                                        @input='changeHS'
                                        prop='hsCode'
                                        placeholder='请填写完整的海关商品品类'
                                ></el-autocomplete>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span='12'>
                            <el-form-item prop='hsName' label='商品名称'>
                                <el-input v-model='goodsForm.hsName' class='normal-input'
                                          placeholder='公司自主填写的商品'></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span='12'>
                            <el-form-item label='规格型号'>
                                <el-input v-model='goodsForm.specification' class='normal-input'></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span='12'>
                            <el-form-item prop='isOwm' label='自有品牌'>
                                <el-select
                                        v-model='goodsForm.isOwm'
                                        placeholder='请选择是否为自有品牌'
                                        filterable
                                        clearable
                                        class='normal-input'
                                >
                                    <el-option
                                            v-for='item in options'
                                            :key='item.id'
                                            :label='item.name'
                                            :value='item.id'
                                    ></el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span='12'>
                            <el-form-item prop='amount' label='订单数量'>
                                <el-input
                                        type='number'
                                        v-model='goodsForm.amount'
                                        @blur='countPrice'
                                        class='normal-input'
                                ></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span='24'>
                            <el-form-item prop='unitPrice' label='成交单价'>
                                <el-input
                                        type='number'
                                        v-model='goodsForm.unitPrice'
                                        @blur='countPrice'
                                        class='normal-input'
                                >
                                    <el-input slot='append' v-text='price' disabled></el-input>
                                </el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span='24'>
                            <el-form-item prop='totalPrice' label='成交总价'>
                                <el-input
                                        type='number'
                                        v-model='goodsForm.totalPrice'
                                        class='normal-input'
                                >
                                    <el-input slot='append' v-text='price' disabled></el-input>
                                </el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span='12'>
                            <el-form-item label='统计单位'>
                                <el-input v-model='goodsForm.statisticUnits' class='normal-input'></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span='12'>
                            <el-form-item label='货源地'>
                                <el-select
                                        v-model='goodsForm.originalGoodsPlace'
                                        :placeholder='goodsForm.show1'
                                        @change='change(21)'
                                        filterable
                                        clearable
                                        class='normal-input'
                                >
                                    <el-option
                                            v-for='item in goodsplace'
                                            :key='item.id'
                                            :label='item.name'
                                            :value='item.id'
                                    ></el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                    </el-row>
                </el-form>
            </div>
            <span slot='footer' class='dialog-footer'>
                <p style="color: red;" v-show="tips_show"><strong>您输入的成交总价已大于1000万，请确认！</strong></p>
        <el-button style='width: 30%;' type='primary' @click="submitDetailForm('goodsForm')">提交</el-button>
      </span>
        </el-dialog>
        <el-dialog title='提示' :visible.sync='deleteDialog' width='30%' center>
            <div style='text-align:center'>是否真的要删除？</div>
            <span slot='footer' class='dialog-footer'>
        <el-button type='danger' @click='deletePost'>删除</el-button>
        <el-button @click='deleteDialog = false'>取消</el-button>
      </span>
        </el-dialog>


        <el-dialog width="200px;" :model="form1" title="" :before-close="beforeClose" :visible.sync="dialogFormVisible">
            <h3>请选择中止订单原因</h3>
            <el-radio-group v-model="form1.radio">
                <el-radio v-for="(item,i) in textArr" :key="i" :label="item">{{item}}</el-radio>
            </el-radio-group>
            <div slot="footer" class="dialog-footer">
                <el-button @click="cancelOrderHandle">取 消</el-button>
                <el-button type="primary" @click="closeOrderHandle">确 定</el-button>
            </div>
        </el-dialog>
    </div>
</template>
<script>
    import {
        getHSoptions,
        getHSInfo,
        getOrderInfoPost,
        getOrderDetailInfoPost,
        getOrderInfo3001,
        getOrderInfo3002,
        getOrderInfo3003,
        updataOrderInfo
    } from '@/api/order';

    export default {
        components: {},

        data() {
            var validChange = (rule, value, callback) => {
                if (this.orderForm.isChange1 == true) {
                    if (!value) {
                        callback(new Error('请选择正确的外商国别'));
                    } else {
                        callback();
                    }
                } else {
                    callback();
                }
            };
            var validateHS = (rule, value, callback) => {
                if (this.hsCode == '') {
                    callback(new Error('请输入正确的海关商品信息'));
                } else if (this.hsFlag == false) {
                    callback(new Error('请输入正确的海关商品信息'));
                } else {
                    callback();
                }
            };
            var validNumber0 = (rule, value, callback) => {
                if (value < 0) {
                    callback(new Error('请输入正确的数值，必须为正数'));
                    this.goodsForm.totalPrice = '';
                } else {
                    callback();
                }
            };
            var validNumber1 = (rule, value, callback) => {
                if (value != '') {
                    if (value < 0) {
                        callback(new Error('请输入正确的数值，必须为正数'));
                        this.goodsForm.unitPrice = '';
                    } else {
                        callback();
                    }
                } else {
                    callback();
                }
            };
            var validNumber2 = (rule, value, callback) => {
                if (value != '') {
                    if (value < 0) {
                        callback(new Error('请输入正确的数值，必须为正数'));
                        this.goodsForm.amount = '';
                    } else {
                        callback();
                    }
                } else {
                    callback();
                }
            };

            var validateDelivery = (rule, value, callback) => {
                if (!value) {
                    callback(new Error('请选择正确的订单交付日期'));
                } else {
                    var beginDate = this.orderForm.orderTime;
                    var endDate = value;
                    var d1 = new Date(beginDate.replace('/-/g/', '/'));
                    var d2 = new Date(endDate.replace('/-/g', '/'));
                    if (beginDate != '' && endDate != '' && d1 > d2) {
                        callback(new Error('请选择正确的订单交付日期'));
                    } else {
                        callback();
                    }
                }
            };
            return {
                dialogFormVisible:false,
                tips_show:false,
                tmpModel: false,
                ctrBtn1: false,
                reason:'',
                options: [
                    {
                        id: '1',
                        name: '非自有品牌'
                    },
                    {
                        id: '2',
                        name: '自有品牌'
                    }
                ],
                hsFlag: false,
                hsCode: '',
                price: '美元',
                deleteID: -1,
                companyID: '',
                orderID: '',

                form1:{
                    region: '',
                    radio:'',
                },
                textArr:['汇率', '外商', '产能', '物流', '市场', '其他'],
                orderForm: {
                    view1: '',
                    view2: '',
                    view3: '',
                    view4: '',
                    view5: '',
                    view6: '',
                    view7: '',
                    view8: '',
                    view9: '',
                    view10: '',
                    view11: '',
                    view12: '',
                    isChange1: false,
                    isChange2: false,
                    isChange3: false,
                    isChange4: false,
                    isChange5: false,
                    isChange6: false,
                    isChange7: false,
                    isChange8: false,
                    isChange9: false,
                    isChange10: false,
                    isChange11: false,
                    isChange12: false,
                    show1: '获取数据中，请稍后...',
                    show2: '获取数据中，请稍后...',
                    show3: '获取数据中，请稍后...',
                    show4: '获取数据中，请稍后...',
                    show5: '获取数据中，请稍后...',
                    show6: '获取数据中，请稍后...',
                    show7: '获取数据中，请稍后...',
                    show8: '获取数据中，请稍后...',
                    show9: '获取数据中，请稍后...',
                    show10: '获取数据中，请稍后...',
                    show11: '获取数据中，请稍后...',
                    show12: '获取数据中，请稍后...',
                    orderNum: '',
                    orderTime: '',
                    deliveryTime: '',
                    isTop: false,
                    meno: '',
                    fb4: '',
                    fb1:''
                },
                goodsDialog: false,
                deleteDialog: false,
                goodsForm: {
                    id: '', //商品id
                    hsCode: '', //海关商品编码
                    hsName: '', //海关商品品名
                    specification: '', //规格型号
                    isOwm: '', //是否自有品牌 1-不是2-是
                    amount: '', //订单数量
                    statisticUnits: '', //统计单位
                    unitPrice: '', //交单价
                    totalPrice: '', //成交总价
                    originalGoodsPlace: '', //货源地
                    show1: '获取数据中，请稍后...',
                    isChange1: false
                },
                goodsplace: [],
                countries: [],
                customs: [],
                startPort: [],
                endCountry: [],
                endPort: [],
                myfs: [],
                jgtk: [],
                bzfs: [],
                ysfs: [],
                ddbz: [],
                shfs: [],
                yszffs: [],
                goodsList: [],
                rules: {

                    orderNum: [
                        {required: true, message: '请填写企业订单编号', trigger: 'blur'}
                    ],
                    view1: [
                        {required: true, validator: validChange, trigger: 'change'}
                    ],
                    orderTime: [
                        {required: true, message: '请填写正确的订单日期', trigger: 'blur'}
                    ],
                    deliveryTime: [
                        {required: true, validator: validateDelivery, trigger: 'blur'}
                    ],
                    view4: [
                        {required: true, message: '请输入订单商品抵运国', trigger: 'blur'}
                    ],
                    view10: [
                        {required: true, message: '请输入正确的订单币种', trigger: 'blur'}
                    ],
                    hsCode: [
                        {required: true, validator: validateHS, trigger: 'change'}
                    ],
                    hsName: [
                        {required: true, message: '请输入正确的商品名称', trigger: 'blur'}
                    ],
                    totalPrice: [
                        {required: true, validator: validNumber0, trigger: 'blur'}
                    ],
                    unitPrice: [
                        {required: false, validator: validNumber1, trigger: 'blur'}
                    ],
                    amount: [
                        {required: false, validator: validNumber2, trigger: 'blur'}
                    ],
                    isOwm: [
                        {required: true, message: '请选择是否为自有品牌', trigger: 'blur'}
                    ]
                },
                total: 0,
                count: 0,
                pageCurrent: 1,
                size: 1000,
                loading: false
            };
        },
        created() {
            this.companyID = localStorage.getItem('companyID');
            this.orderID = localStorage.getItem('orderID');
            // //初始化列表
            this.initOrderChange();
            if (this.orderID === null || this.orderID == '') {
                // 以新增模式打开
                this.clearAll();
            } else {
                this.getOrderInfo(this.orderID);
                this.getOrderDetailInfo(this.orderID, '1');
                // 加入编辑模式
            }
            ;
        },
        watch: {
            $route(to, from) {
                console.log('Route ', from);
                let that = this;
                var orderid = to;
                if (orderid.name == 'orderCreate') {
                    that.orderID = localStorage.getItem('orderID');
                    if (that.orderID == 'undefined' || that.orderID == null) {
                        // 以新增模式打开
                        that.clearAll();
                    } else {
                        that.getOrderInfo(that.orderID);
                        that.getOrderDetailInfo(that.orderID, '1');
                        // 加入编辑模式
                    }
                }
            },
            'goodsForm.totalPrice':function () {
                if(this.goodsForm.totalPrice>10000000){
                    this.tips_show = true;
                }else{
                    this.tips_show = false;
                };
            }
        },
        methods: {
            beforeClose(){
                this.dialogFormVisible = false;
                this.orderForm.fb1 ='';
            },
            changeValue(l){
                console.log(l)
            },
            copyHandle(row){
              let arr = [];
              arr = this.goodsList;
              row.id = '';
              arr.push(row);
              this.goodsList = arr;
              this.total = this.goodsList.length;
            },
            tmpHandle(){
                this.tmpModel =true;
                this.getTmpModel();

            },
            tmpHandle2(){

                //终止订单
                this.dialogFormVisible =true;
                // this.getTmpModel();
            },
            cancelOrderHandle(){
                this.dialogFormVisible = false;
                this.orderForm.fb1 ='';
            },
            closeOrderHandle(){
                if(this.form1.radio){
                    this.orderForm.fb1=2;
                    this.submitForm('orderForm','2');
                }else{
                    this.$message.error('请选择终止订单的原因')
                    return;
                }

            },
            getTmpModel() {
                if (this.tmpModel) {

                    this.rules = {};
                    this.submitForm('orderForm','0');
                } else {
                    var validChange = (rule, value, callback) => {
                        if (this.orderForm.isChange1 == true) {
                            if (!value) {
                                callback(new Error('请选择正确的外商国别'));
                            } else {
                                callback();
                            }
                        } else {
                            callback();
                        }
                    };
                    var validateHS = (rule, value, callback) => {
                        if (this.hsCode == '') {
                            callback(new Error('请输入正确的海关商品信息'));
                        } else if (this.hsFlag == false) {
                            callback(new Error('请输入正确的海关商品信息'));
                        } else {
                            callback();
                        }
                    };
                    var validNumber0 = (rule, value, callback) => {
                        if (value < 0) {
                            callback(new Error('请输入正确的数值，必须为正数'));
                            this.goodsForm.totalPrice = '';
                        } else {
                            callback();
                        }
                    };
                    var validNumber1 = (rule, value, callback) => {
                        if (value != '') {
                            if (value < 0) {
                                callback(new Error('请输入正确的数值，必须为正数'));
                                this.goodsForm.unitPrice = '';
                            } else {
                                callback();
                            }
                        } else {
                            callback();
                        }
                    };
                    var validNumber2 = (rule, value, callback) => {
                        if (value != '') {
                            if (value < 0) {
                                callback(new Error('请输入正确的数值，必须为正数'));
                                this.goodsForm.amount = '';
                            } else {
                                callback();
                            }
                        } else {
                            callback();
                        }
                    };

                    var validateDelivery = (rule, value, callback) => {
                        if (!value) {
                            callback(new Error('请选择正确的订单交付日期'));
                        } else {
                            var beginDate = this.orderForm.orderTime;
                            var endDate = value;
                            var d1 = new Date(beginDate.replace('/-/g/', '/'));
                            var d2 = new Date(endDate.replace('/-/g', '/'));
                            if (beginDate != '' && endDate != '' && d1 > d2) {
                                callback(new Error('请选择正确的订单交付日期'));
                            } else {
                                callback();
                            }
                        }
                    };
                    this.rules = {
                        orderNum: [
                            {required: true, message: '请填写企业订单编号', trigger: 'blur'}
                        ],
                        view1: [
                            {required: true, validator: validChange, trigger: 'change'}
                        ],
                        orderTime: [
                            {required: true, message: '请填写正确的订单日期', trigger: 'blur'}
                        ],
                        deliveryTime: [
                            {required: true, validator: validateDelivery, trigger: 'blur'}
                        ],
                        view4: [
                            {required: true, message: '请输入订单商品抵运国', trigger: 'blur'}
                        ],
                        view10: [
                            {required: true, message: '请输入正确的订单币种', trigger: 'blur'}
                        ],
                        hsCode: [
                            {required: true, validator: validateHS, trigger: 'change'}
                        ],
                        hsName: [
                            {required: true, message: '请输入正确的商品名称', trigger: 'blur'}
                        ],
                        totalPrice: [
                            {required: true, validator: validNumber0, trigger: 'blur'}
                        ],
                        unitPrice: [
                            {required: false, validator: validNumber1, trigger: 'blur'}
                        ],
                        amount: [
                            {required: false, validator: validNumber2, trigger: 'blur'}
                        ],
                        isOwm: [
                            {required: true, message: '请选择是否为自有品牌', trigger: 'blur'}
                        ]
                    };
                }
            },
            countPrice() {
                let that = this;
                if (this.goodsForm.amount != '' && this.goodsForm.unitPrice != '') {
                    let r = /^\d+$/;
                   /* if (r.test(this.goodsForm.amount)) {
                        this.goodsForm.amount = this.goodsForm.amount;
                    } else {
                        this.goodsForm.amount = parseInt(this.goodsForm.amount)
                    }
                    ;*/
                    let _num = ((that.goodsForm.amount * 10000) * (that.goodsForm.unitPrice * 10000)) / 100000000;
                    that.goodsForm.totalPrice = parseFloat(Number(_num).toFixed(4))

                };
                if(this.goodsForm.unitPrice && this.goodsForm.unitPrice>0){
                    this.goodsForm.unitPrice = parseFloat(Number(this.goodsForm.unitPrice).toFixed(4))
                };
                if(this.goodsForm.amount&&this.goodsForm.amount>0){
                    this.goodsForm.amount = parseFloat(Number(this.goodsForm.amount).toFixed(4))
                }

            },

            changeCountries() {
                if (this.orderForm.isChange1 == false && this.countries.length > 0) {
                    this.orderForm.isChange1 = true;
                }
            },
            // 当前的页码，改变时会触发
            handleCurrentChange: function (currentPage) {
                this.getOrderDetailInfo(this.orderID, currentPage);
            },
            change(type) {
                if (type == 2) {
                    this.orderForm.isChange2 = true;
                } else if (type == 3) {
                    this.orderForm.isChange3 = true;
                } else if (type == 4) {
                    this.orderForm.isChange4 = true;
                } else if (type == 5) {
                    this.orderForm.isChange5 = true;
                } else if (type == 6) {
                    this.orderForm.isChange6 = true;
                } else if (type == 7) {
                    this.orderForm.isChange7 = true;
                } else if (type == 8) {
                    this.orderForm.isChange8 = true;
                } else if (type == 9) {
                    this.orderForm.isChange9 = true;
                } else if (type == 10) {
                    this.orderForm.isChange10 = true;
                    //修改了货币
                    let obj = {};
                    obj = this.ddbz.find(item => {
                        return item.id === this.orderForm.view10; //筛选出匹配数据
                    });
                    if (obj != null) {
                        this.price = obj.name;
                    }
                } else if (type == 11) {
                    this.orderForm.isChange11 = true;
                } else if (type == 12) {
                    this.orderForm.isChange12 = true;
                } else if (type == 21) {
                    //货源地
                    this.goodsForm.isChange1 = true;
                }
            },
            handleCreateGoods(index, row) {
                let that = this;
                var bFlag = true;
                if (that.orderForm.view10 == '' || that.orderForm.view10 == null) {
                    this.$message.error('请输入正确的订单币种信息!');
                    bFlag = false;
                }
                if (bFlag == true) {
                    if (row == '') {
                        that.deleteID = -1;
                        that.goodsForm.id = '';
                        that.goodsForm.hsCode = '';
                        that.goodsForm.hsName = '';
                        that.goodsForm.specification = '';
                        that.goodsForm.isOwm = '';
                        that.goodsForm.amount = '';
                        that.goodsForm.statisticUnits = '';
                        that.goodsForm.unitPrice = '';
                        that.goodsForm.totalPrice = '';
                        that.goodsForm.originalGoodsPlace = '';
                    } else {
                        that.deleteID = index;
                        that.goodsForm.hsCode = row.hsCode;
                        //转换为HS信息
                        that.querySearchHSName(that.goodsForm.hsCode);
                        that.goodsForm.hsName = row.hsName;
                        that.goodsForm.specification = row.specification;
                        that.goodsForm.isOwm = row.isOwm == '是' ? '2' : '1';
                        that.goodsForm.amount = row.amount;
                        that.goodsForm.statisticUnits = row.statisticUnits;
                        that.goodsForm.unitPrice = row.unitPrice;
                        that.goodsForm.totalPrice = row.totalPrice;
                        that.goodsForm.originalGoodsPlace = row.originalGoodsPlace;
                        if (that.goodsplace.length > 0) {
                            var obj = {};
                            obj = that.goodsplace.find(item => {
                                return item.name === that.goodsForm.originalGoodsPlace; //筛选出匹配数据
                            });
                            if (obj == null) {
                                obj = that.goodsplace.find(item => {
                                    return item.id === that.goodsForm.originalGoodsPlace; //筛选出匹配数据
                                });
                                if (obj != null) {
                                    that.goodsForm.originalGoodsPlace = obj.name;
                                }
                            } else {
                                that.goodsForm.originalGoodsPlace = obj.id;
                            }
                        }
                    }
                    that.goodsDialog = true;
                }
            },
            handleDeleteGoods(index) {
                this.deleteID = index;
                this.deleteDialog = true;

            },
            deletePost() {
                // this.deleteID = '';
                //删除一行商品
                this.goodsList.splice(this.deleteID, 1);
                this.deleteDialog = false;
                this.total = this.goodsList.length;
            },
            submitDetailForm(formName) {
                this.total = this.goodsList.length;
                if(this.goodsForm.totalPrice<0 || !this.goodsForm.totalPrice){
                    this.$message.error('成交总价不能为空!');
                    return;
                };
                if(this.goodsForm.hsName=='' || !this.goodsForm.hsName){
                    this.$message.error('商品名称不能为空!');
                    return;
                };

                let that = this;
                var bFlag = true;
                if (!that.hsFlag) {
                    this.$message.error('请输入正确的海关商品信息!');
                    bFlag = false;
                }
                //计算总价
                if (bFlag == true) {
                    if (
                        that.goodsForm.totalPrice == '' ||
                        that.goodsForm.totalPrice == null
                    ) {
                        if (that.goodsForm.amount != '' && that.goodsForm.unitPrice != '') {
                            that.goodsForm.totalPrice =
                                that.goodsForm.amount * that.goodsForm.unitPrice;
                        }
                    }
                    that.loading = true;
                    that.$refs[formName].validate(valid => {
                        if (valid) {
                            var map = {
                                id: '',
                                hsCode: that.hsCode,
                                hsName: that.goodsForm.hsName,
                                specification: that.goodsForm.specification,
                                isOwm: that.goodsForm.isOwm == '2' ? '是' : '否',
                                amount: that.goodsForm.amount,
                                statisticUnits: that.goodsForm.statisticUnits,
                                unitPrice: that.goodsForm.unitPrice,
                                totalPrice: that.goodsForm.totalPrice,
                                originalGoodsPlace: that.goodsForm.originalGoodsPlace
                            };
                            if (that.goodsplace.length > 0) {
                                var obj = {};
                                obj = that.goodsplace.find(item => {
                                    return item.id === map.originalGoodsPlace; //筛选出匹配数据
                                });
                                if (obj != null) {
                                    map.originalGoodsPlace = obj.name;
                                }
                            }
                            if (that.deleteID < 0) {
                                that.goodsList.push(map);
                            } else {
                                var id = that.goodsList[that.deleteID].id;
                                map.id = id;
                                that.goodsList.splice(that.deleteID, 1, map);
                            }
                            that.goodsDialog = false;
                        }
                    });
                }
                that.loading = false;
            },
            submitForm(formName, type) {
                let that = this;
                var bFlag = true;
                that.loading = true;
                if (type == '2' || type == '1') {
                    if (that.goodsList.length <= 0) {
                        this.ctrBtn1 = false;
                        this.$message.error('请输入正确的订单出口商品信息!');
                        bFlag = false;
                    }
                } else {
                    this.ctrBtn1 = false;
                    if (this.orderForm.orderNum == '' || !this.orderForm.orderNum) {
                        this.$message.error('请填写订单编号再提交');
                        return;
                    }
                }
                if (bFlag == true) {
                    if (type == '2') {

                        that.$refs[formName].validate(valid => {
                            var validChange = (rule, value, callback) => {
                                if (this.orderForm.isChange1 == true) {
                                    if (!value) {
                                        callback(new Error('请选择正确的外商国别'));
                                    } else {
                                        callback();
                                    }
                                } else {
                                    callback();
                                }
                            };
                            var validateHS = (rule, value, callback) => {
                                if (this.hsCode == '') {
                                    callback(new Error('请输入正确的海关商品信息'));
                                } else if (this.hsFlag == false) {
                                    callback(new Error('请输入正确的海关商品信息'));
                                } else {
                                    callback();
                                }
                            };
                            var validNumber0 = (rule, value, callback) => {
                                if (value < 0) {
                                    callback(new Error('请输入正确的数值，必须为正数'));
                                    this.goodsForm.totalPrice = '';
                                } else {
                                    callback();
                                }
                            };
                            var validNumber1 = (rule, value, callback) => {
                                if (value != '') {
                                    if (value < 0) {
                                        callback(new Error('请输入正确的数值，必须为正数'));
                                        this.goodsForm.unitPrice = '';
                                    } else {
                                        callback();
                                    }
                                } else {
                                    callback();
                                }
                            };
                            var validNumber2 = (rule, value, callback) => {
                                if (value != '') {
                                    if (value < 0) {
                                        callback(new Error('请输入正确的数值，必须为正数'));
                                        this.goodsForm.amount = '';
                                    } else {
                                        callback();
                                    }
                                } else {
                                    callback();
                                }
                            };

                            var validateDelivery = (rule, value, callback) => {
                                if (!value) {
                                    callback(new Error('请选择正确的订单交付日期'));
                                } else {
                                    var beginDate = this.orderForm.orderTime;
                                    var endDate = value;
                                    var d1 = new Date(beginDate.replace('/-/g/', '/'));
                                    var d2 = new Date(endDate.replace('/-/g', '/'));
                                    if (beginDate != '' && endDate != '' && d1 > d2) {
                                        callback(new Error('请选择正确的订单交付日期'));
                                    } else {
                                        callback();
                                    }
                                }
                            };
                            this.rules = {

                                orderNum: [
                                    {required: true, message: '请填写企业订单编号', trigger: 'blur'}
                                ],
                                view1: [
                                    {required: true, validator: validChange, trigger: 'change'}
                                ],
                                orderTime: [
                                    {required: true, message: '请填写正确的订单日期', trigger: 'blur'}
                                ],
                                deliveryTime: [
                                    {required: true, validator: validateDelivery, trigger: 'blur'}
                                ],
                                view4: [
                                    {required: true, message: '请输入订单商品抵运国', trigger: 'blur'}
                                ],
                                view10: [
                                    {required: true, message: '请输入正确的订单币种', trigger: 'blur'}
                                ],
                                hsCode: [
                                    {required: true, validator: validateHS, trigger: 'change'}
                                ],
                                hsName: [
                                    {required: true, message: '请输入正确的商品名称', trigger: 'blur'}
                                ],
                                totalPrice: [
                                    {required: true, validator: validNumber0, trigger: 'blur'}
                                ],
                                unitPrice: [
                                    {required: false, validator: validNumber1, trigger: 'blur'}
                                ],
                                amount: [
                                    {required: false, validator: validNumber2, trigger: 'blur'}
                                ],
                                isOwm: [
                                    {required: true, message: '请选择是否为自有品牌', trigger: 'blur'}
                                ]
                            };
                            if (valid) {
                                var oid = that.orderID;
                                var modify = true;
                                if (this.orderID === null || this.orderID == '') {
                                    modify = false;
                                }
                                var details = that.goodsList;
                                for (var i = 0; i < details.length; i++) {
                                    var map = details[i];
                                    map.isOwm = map.isOwm == '是' ? '2' : '1';
                                    map.id = '';
                                    if (that.goodsplace.length > 0) {
                                        var obj = {};
                                        obj = that.goodsplace.find(item => {
                                            return item.name === map.originalGoodsPlace; //筛选出匹配数据
                                        });
                                        if (obj != null) {
                                            map.originalGoodsPlace = obj.id;
                                        }
                                    }
                                    details.splice(i, 1, map);
                                }
                                details = JSON.stringify(details);
                                //注册
                                updataOrderInfo(
                                    oid,
                                    modify,
                                    that.orderForm.orderNum, // orderCodeCmp	[string]	是	企业订单编号
                                    '', // orderName	[string]	是	订单名称
                                    '', // foreignBusi	[string]	是	外商名称
                                    that.orderForm.isChange1 == true
                                        ? that.orderForm.view1
                                        : '', // foreignCountry	[string]	是	外商国别
                                    that.orderForm.isChange2 == true
                                        ? that.orderForm.view2
                                        : '', // declareCustoms	[string]	是	报关地海关
                                    that.orderForm.isChange3 == true
                                        ? that.orderForm.view3
                                        : '', // portLoading	[string]	是	起运港
                                    that.orderForm.isChange4 == true
                                        ? that.orderForm.view4
                                        : '', // arrivalCountry	[string]	是	抵运国
                                    that.orderForm.isChange5 == true
                                        ? that.orderForm.view5
                                        : '', // portDestination	[string]	是	目的港
                                    that.orderForm.isChange6 == true
                                        ? that.orderForm.view6
                                        : '', // tradeMode	[string]	是	贸易方式
                                    that.orderForm.isChange7 == true
                                        ? that.orderForm.view7
                                        : '', // priceClause	[string]	是	价格条款
                                    that.orderForm.isChange8 == true
                                        ? that.orderForm.view8
                                        : '', // packingMode	[string]	是	包装方式
                                    that.orderForm.isChange9 == true
                                        ? that.orderForm.view9
                                        : '', // transportMode	[string]	是	运输方式
                                    that.orderForm.isChange10 == true
                                        ? that.orderForm.view10
                                        : '', // orderCurrency	[string]	是	订单币种
                                    that.orderForm.isChange11 == true
                                        ? that.orderForm.view11
                                        : '', // receiptMode	[string]	是	收汇方式
                                    that.orderForm.isChange12 == true
                                        ? that.orderForm.view12
                                        : '', // transportPaymentMode	[string]	是	运输支付方式
                                    that.orderForm.isTop == true ? '2' : '1', // isInsure	[string]	是	是否投保中信保 1没投过，2投过
                                    type, // applicationState	[string]	是	申报状态 1未申报，2已申报
                                    that.orderForm.deliveryTime, // deliveryTime	[string]	是	交货日期
                                    that.orderForm.orderTime, // orderTime	[string]	是	订单日期
                                    details, // products
                                    that.orderForm.meno,//备注
                                    that.orderForm.fb4, //关联报关单
                                    that.orderForm.fb1
                                )
                                    .then(data => {
                                        that.loading = false;
                                        console.log('订单提交成功', data);
                                        that.orderForm.fb4 = ''
                                        this.tmpModel=false;
                                        that.orderForm.fb1=''

                                     window.location.href='/company/orderlist'
                                    })
                                    .catch(function (error) {
                                        console.log(error);
                                        that.loading = false;
                                    });
                            } else {
                                if(!this.orderForm.orderNum){
                                    this.$message.error('订单编号不能为空!');
                                    return;
                                }
                                if(!this.orderForm.view1){
                                    this.$message.error('外商国别不能为空!');
                                    return;
                                }
                                if(!this.orderForm.orderTime){
                                    this.$message.error('订单日期不能为空!');
                                    return;
                                }
                                if(!this.orderForm.deliveryTime){
                                    this.$message.error('交货日期不能为空!');
                                    return;
                                }
                                if(!this.orderForm.view4){
                                    this.$message.error('抵运国不能为空!');
                                    return;
                                }
                                if(!this.orderForm.view10){
                                    this.$message.error('订单币种不能为空!');
                                    return;
                                }
                            }
                        });

                      /*  that
                            .$confirm('申报之后不可以改变订单的信息!', '提示', {
                                confirmButtonText: '确定',
                                cancelButtonText: '取消',
                                type: 'warning'
                            })
                            .then(() => {

                            })
                            .catch(() => {
                                console.log('');
                            });*/
                    } else {
                        that.$refs[formName].validate(valid => {
                            if (valid) {
                                var oid = that.orderID;
                                var modify = true;
                                if (this.orderID === null || this.orderID == '') {
                                    modify = false;
                                }
                                var details = that.goodsList;
                                for (var i = 0; i < details.length; i++) {
                                    var map = details[i];
                                    map.isOwm = map.isOwm == '是' ? '2' : '1';
                                    map.id = '';
                                    if (that.goodsplace.length > 0) {
                                        var obj = {};
                                        obj = that.goodsplace.find(item => {
                                            return item.name === map.originalGoodsPlace; //筛选出匹配数据
                                        });
                                        if (obj != null) {
                                            map.originalGoodsPlace = obj.id;
                                        }
                                    }
                                    details.splice(i, 1, map);
                                }
                                details = JSON.stringify(details);
                                //注册
                                updataOrderInfo(
                                    oid,
                                    modify,
                                    that.orderForm.orderNum, // orderCodeCmp	[string]	是	企业订单编号
                                    '', // orderName	[string]	是	订单名称
                                    '', // foreignBusi	[string]	是	外商名称
                                    that.orderForm.isChange1 == true ? that.orderForm.view1 : '', // foreignCountry	[string]	是	外商国别
                                    that.orderForm.isChange2 == true ? that.orderForm.view2 : '', // declareCustoms	[string]	是	报关地海关
                                    that.orderForm.isChange3 == true ? that.orderForm.view3 : '', // portLoading	[string]	是	起运港
                                    that.orderForm.isChange4 == true ? that.orderForm.view4 : '', // arrivalCountry	[string]	是	抵运国
                                    that.orderForm.isChange5 == true ? that.orderForm.view5 : '', // portDestination	[string]	是	目的港
                                    that.orderForm.isChange6 == true ? that.orderForm.view6 : '', // tradeMode	[string]	是	贸易方式
                                    that.orderForm.isChange7 == true ? that.orderForm.view7 : '', // priceClause	[string]	是	价格条款
                                    that.orderForm.isChange8 == true ? that.orderForm.view8 : '', // packingMode	[string]	是	包装方式
                                    that.orderForm.isChange9 == true ? that.orderForm.view9 : '', // transportMode	[string]	是	运输方式
                                    that.orderForm.isChange10 == true ? that.orderForm.view10 : '', // orderCurrency	[string]	是	订单币种
                                    that.orderForm.isChange11 == true ? that.orderForm.view11 : '', // receiptMode	[string]	是	收汇方式
                                    that.orderForm.isChange12 == true ? that.orderForm.view12 : '', // transportPaymentMode	[string]	是	运输支付方式
                                    that.orderForm.isTop == true ? '2' : '1', // isInsure	[string]	是	是否投保中信保 1没投过，2投过
                                    type, // applicationState	[string]	是	申报状态 1未申报，2已申报
                                    that.orderForm.deliveryTime, // deliveryTime	[string]	是	交货日期
                                    that.orderForm.orderTime, // orderTime	[string]	是	订单日期
                                    details, // products
                                    that.orderForm.meno,//备注
                                    that.orderForm.fb4, //关联报关单
                                    that.orderForm.fb1
                                )
                                    .then(data => {
                                        that.loading = false;
                                        that.orderForm.fb4 = ''
                                        var validChange = (rule, value, callback) => {
                                            if (this.orderForm.isChange1 == true) {
                                                if (!value) {
                                                    callback(new Error('请选择正确的外商国别'));
                                                } else {
                                                    callback();
                                                }
                                            } else {
                                                callback();
                                            }
                                        };
                                        var validateHS = (rule, value, callback) => {
                                            if (this.hsCode == '') {
                                                callback(new Error('请输入正确的海关商品信息'));
                                            } else if (this.hsFlag == false) {
                                                callback(new Error('请输入正确的海关商品信息'));
                                            } else {
                                                callback();
                                            }
                                        };
                                        var validNumber0 = (rule, value, callback) => {
                                            if (value < 0) {
                                                callback(new Error('请输入正确的数值，必须为正数'));
                                                this.goodsForm.totalPrice = '';
                                            } else {
                                                callback();
                                            }
                                        };
                                        var validNumber1 = (rule, value, callback) => {
                                            if (value != '') {
                                                if (value < 0) {
                                                    callback(new Error('请输入正确的数值，必须为正数'));
                                                    this.goodsForm.unitPrice = '';
                                                } else {
                                                    callback();
                                                }
                                            } else {
                                                callback();
                                            }
                                        };
                                        var validNumber2 = (rule, value, callback) => {
                                            if (value != '') {
                                                if (value < 0) {
                                                    callback(new Error('请输入正确的数值，必须为正数'));
                                                    this.goodsForm.amount = '';
                                                } else {
                                                    callback();
                                                }
                                            } else {
                                                callback();
                                            }
                                        };

                                        var validateDelivery = (rule, value, callback) => {
                                            if (!value) {
                                                callback(new Error('请选择正确的订单交付日期'));
                                            } else {
                                                var beginDate = this.orderForm.orderTime;
                                                var endDate = value;
                                                var d1 = new Date(beginDate.replace('/-/g/', '/'));
                                                var d2 = new Date(endDate.replace('/-/g', '/'));
                                                if (beginDate != '' && endDate != '' && d1 > d2) {
                                                    callback(new Error('请选择正确的订单交付日期'));
                                                } else {
                                                    callback();
                                                }
                                            }
                                        };
                                        this.rules = {

                                            orderNum: [
                                                {required: true, message: '请填写企业订单编号', trigger: 'blur'}
                                            ],
                                            view1: [
                                                {required: true, validator: validChange, trigger: 'change'}
                                            ],
                                            orderTime: [
                                                {required: true, message: '请填写正确的订单日期', trigger: 'blur'}
                                            ],
                                            deliveryTime: [
                                                {required: true, validator: validateDelivery, trigger: 'blur'}
                                            ],
                                            view4: [
                                                {required: true, message: '请输入订单商品抵运国', trigger: 'blur'}
                                            ],
                                            view10: [
                                                {required: true, message: '请输入正确的订单币种', trigger: 'blur'}
                                            ],
                                            hsCode: [
                                                {required: true, validator: validateHS, trigger: 'change'}
                                            ],
                                            hsName: [
                                                {required: true, message: '请输入正确的商品名称', trigger: 'blur'}
                                            ],
                                            totalPrice: [
                                                {required: true, validator: validNumber0, trigger: 'blur'}
                                            ],
                                            unitPrice: [
                                                {required: false, validator: validNumber1, trigger: 'blur'}
                                            ],
                                            amount: [
                                                {required: false, validator: validNumber2, trigger: 'blur'}
                                            ],
                                            isOwm: [
                                                {required: true, message: '请选择是否为自有品牌', trigger: 'blur'}
                                            ]
                                        };
                                        this.tmpModel=false;
                                     window.location.href='/company/orderlist'

                                    })
                                    .catch(function (error) {
                                        console.log(error);
                                        that.loading = false;
                                    });
                            }else {
                                var oid = that.orderID;
                                var modify = true;
                                if (this.orderID === null || this.orderID == '') {
                                    modify = false;
                                }
                                var details = that.goodsList;
                                for (var i = 0; i < details.length; i++) {
                                    var map = details[i];
                                    map.isOwm = map.isOwm == '是' ? '2' : '1';
                                    if (that.goodsplace.length > 0) {
                                        var obj = {};
                                        obj = that.goodsplace.find(item => {
                                            return item.name === map.originalGoodsPlace; //筛选出匹配数据
                                        });
                                        if (obj != null) {
                                            map.originalGoodsPlace = obj.id;
                                        }
                                    }
                                    details.splice(i, 1, map);
                                }
                                details = JSON.stringify(details);
                                //注册
                                updataOrderInfo(
                                    oid,
                                    modify,
                                    that.orderForm.orderNum, // orderCodeCmp	[string]	是	企业订单编号
                                    '', // orderName	[string]	是	订单名称
                                    '', // foreignBusi	[string]	是	外商名称
                                    that.orderForm.isChange1 == true ? that.orderForm.view1 : '', // foreignCountry	[string]	是	外商国别
                                    that.orderForm.isChange2 == true ? that.orderForm.view2 : '', // declareCustoms	[string]	是	报关地海关
                                    that.orderForm.isChange3 == true ? that.orderForm.view3 : '', // portLoading	[string]	是	起运港
                                    that.orderForm.isChange4 == true ? that.orderForm.view4 : '', // arrivalCountry	[string]	是	抵运国
                                    that.orderForm.isChange5 == true ? that.orderForm.view5 : '', // portDestination	[string]	是	目的港
                                    that.orderForm.isChange6 == true ? that.orderForm.view6 : '', // tradeMode	[string]	是	贸易方式
                                    that.orderForm.isChange7 == true ? that.orderForm.view7 : '', // priceClause	[string]	是	价格条款
                                    that.orderForm.isChange8 == true ? that.orderForm.view8 : '', // packingMode	[string]	是	包装方式
                                    that.orderForm.isChange9 == true ? that.orderForm.view9 : '', // transportMode	[string]	是	运输方式
                                    that.orderForm.isChange10 == true ? that.orderForm.view10 : '', // orderCurrency	[string]	是	订单币种
                                    that.orderForm.isChange11 == true ? that.orderForm.view11 : '', // receiptMode	[string]	是	收汇方式
                                    that.orderForm.isChange12 == true ? that.orderForm.view12 : '', // transportPaymentMode	[string]	是	运输支付方式
                                    that.orderForm.isTop == true ? '2' : '1', // isInsure	[string]	是	是否投保中信保 1没投过，2投过
                                    type, // applicationState	[string]	是	申报状态 1未申报，2已申报
                                    that.orderForm.deliveryTime, // deliveryTime	[string]	是	交货日期
                                    that.orderForm.orderTime, // orderTime	[string]	是	订单日期
                                    details, // products
                                    that.orderForm.meno,//备注
                                    that.orderForm.fb4, //关联报关单,
                                    that.orderForm.fb1
                                )
                                    .then(data => {
                                        that.loading = false;
                                        that.orderForm.fb4 = ''
                                        this.tmpModel=false;
                                        // this.$router.push({path: '/orderlist'});
                                     window.location.href='/company/orderlist'

                                    })
                                    .catch(function (error) {
                                        console.log(error);
                                        that.loading = false;
                                    });
                            }
                        });
                    }
                }
            },
            initOrderChange() {
                let that = this;
                that.loading = true;
                var lenth = this.goodsList.length;
                that.goodsList.splice(0, lenth);
                //初始化所有选项
                that.orderForm.orderNum = '请输入订单编号';
                that.orderForm.orderTime = that.getCurrentDate(1);
                that.orderForm.deliveryTime = that.getCurrentDate(1);

                //货源地
                getOrderInfo3001('3008') //货源地
                    .then(data => {
                        var myData = data.data;
                        if (myData.length > 0) {
                            //加入数据内容
                            for (let i of myData) {
                                var map = {
                                    id: i.configKey,
                                    name: i.configValue
                                };
                                that.goodsplace.push(map);
                            }
                            that.goodsForm.show1 = '请选择';
                            if (that.goodsList.length > 0) {
                                for (var i = 0; i < that.goodsList.length; i++) {
                                    var mapGL = that.goodsList[i];
                                    var obj = {};
                                    obj = that.goodsplace.find(item => {
                                        return item.id === mapGL.originalGoodsPlace; //筛选出匹配数据
                                    });
                                    if (obj != null) {
                                        mapGL.originalGoodsPlace = obj.name;
                                    }
                                    that.goodsList.splice(i, 1, mapGL);
                                }
                            }
                        }
                    })
                    .catch(function (error) {
                        console.log(error);
                    });

                getOrderInfo3001('3003') //国别地区//已修改
                    .then(data => {
                        var myData = data.data;
                        if (myData.length > 0) {
                            //加入数据内容
                            for (let i of myData) {
                                var map = {
                                    id: i.configKey,
                                    name: i.configValue
                                };
                                that.endCountry.push(map);
                                that.countries.push(map);
                            }
                            that.orderForm.show1 = '请选择';
                            that.orderForm.show4 = '请选择';
                        }
                    })
                    .catch(function (error) {
                        console.log(error);
                    });

                getOrderInfo3002()
                    .then(data => {
                        var myData = data.data;
                        if (myData.length > 0) {
                            //加入数据内容
                            for (let i of myData) {
                                var map = {
                                    id: i.departmentCode,
                                    name: i.departmentName
                                };
                                that.customs.push(map);
                            }
                            that.orderForm.show2 = '请选择';
                        }
                    })
                    .catch(function (error) {
                        console.log(error);
                    });

                getOrderInfo3003() //港口，已修改
                    .then(data => {
                        var myData = data.data;
                        if (myData.length > 0) {
                            //加入数据内容
                            for (let i of myData) {
                                var map = {
                                    id: i.wharfCode,
                                    name: i.wharfName + '(' + i.wharfEnName + ')'
                                };
                                that.startPort.push(map);
                                that.endPort.push(map);
                            }
                            that.orderForm.show3 = '请选择';
                            that.orderForm.show5 = '请选择';
                        }
                    })
                    .catch(function (error) {
                        console.log(error);
                    });

                getOrderInfo3001('3010') //监管方式//已修改
                    .then(data => {
                        var myData = data.data;
                        if (myData.length > 0) {
                            //加入数据内容
                            for (let i of myData) {
                                var map = {
                                    id: i.configKey,
                                    name: i.configValue
                                };
                                that.myfs.push(map);
                            }
                            that.orderForm.show6 = '请选择';
                        }
                    })
                    .catch(function (error) {
                        console.log(error);
                    });

                getOrderInfo3001('3004') //已修改
                    .then(data => {
                        var myData = data.data;
                        if (myData.length > 0) {
                            //加入数据内容
                            for (let i of myData) {
                                var map = {
                                    id: i.configKey,
                                    name: i.configValue
                                };
                                that.jgtk.push(map);
                            }
                            that.orderForm.show7 = '请选择';
                        }
                    })
                    .catch(function (error) {
                        console.log(error);
                    });

                getOrderInfo3001('3011') //已修改
                    .then(data => {
                        var myData = data.data;
                        if (myData.length > 0) {
                            //加入数据内容
                            for (let i of myData) {
                                var map = {
                                    id: i.configKey,
                                    name: i.configValue
                                };
                                that.bzfs.push(map);
                            }
                            that.orderForm.show8 = '请选择';
                        }
                    })
                    .catch(function (error) {
                        console.log(error);
                    });

                getOrderInfo3001('3001') //修改过
                    .then(data => {
                        var myData = data.data;
                        if (myData.length > 0) {
                            //加入数据内容
                            for (let i of myData) {
                                var map = {
                                    id: i.configKey,
                                    name: i.configValue
                                };
                                that.ddbz.push(map);
                            }
                            that.orderForm.show10 = '请选择';
                        }
                    })
                    .catch(function (error) {
                        console.log(error);
                    });

                getOrderInfo3001('3009') //已修改
                    .then(data => {
                        var myData = data.data;
                        if (myData.length > 0) {
                            //加入数据内容
                            for (let i of myData) {
                                var map = {
                                    id: i.configKey,
                                    name: i.configValue
                                };
                                that.shfs.push(map);
                                that.yszffs.push(map); //运输支付方式
                            }
                            that.orderForm.show11 = '请选择';
                            that.orderForm.show12 = '请选择';
                        }
                    })
                    .catch(function (error) {
                        console.log(error);
                    });

                getOrderInfo3001('3005') //已修改
                    .then(data => {
                        var myData = data.data;
                        if (myData.length > 0) {
                            //加入数据内容
                            for (let i of myData) {
                                var map = {
                                    id: i.configKey,
                                    name: i.configValue
                                };
                                that.ysfs.push(map);
                            }
                            that.orderForm.show9 = '请选择';
                        }
                    })
                    .catch(function (error) {
                        console.log(error);
                    });
                that.loading = false;
            },
            //初始化数据
            getOrderInfo(orderID) {
                let that = this;
                that.loading = true;
                getOrderInfoPost(orderID)
                    .then(data => {
                        that.loading = false;
                        var myData = data.data;
                        if (myData === null) {
                            that.clearAll();
                        } else {
                            //加入数据内容
                            that.orderForm.orderNum = myData.orderCodeCmp;
                            that.orderForm.orderTime = myData.orderTime;
                            that.orderForm.deliveryTime = myData.deliveryTime;
                            that.orderForm.view1 = myData.foreignCountry;
                            that.orderForm.view2 = myData.declareCustoms;
                            that.orderForm.view3 = myData.portLoading;
                            that.orderForm.view4 = myData.arrivalCountry;
                            that.orderForm.view5 = myData.portDestination;
                            that.orderForm.view6 = myData.tradeMode;
                            that.orderForm.view7 = myData.priceClause;
                            that.orderForm.view8 = myData.packingMode;
                            that.orderForm.view9 = myData.transportMode;
                            that.orderForm.view10 = myData.orderCurrency;
                            that.orderForm.fb4 = myData.fb4;
                            that.orderForm.meno = myData.meno;
                            let obj = {};
                            obj = this.ddbz.find(item => {
                                return item.id === this.orderForm.view10; //筛选出匹配数据
                            });
                            if (obj != null) {
                                this.price = obj.name;
                            }
                            that.orderForm.view11 = myData.receiptMode;
                            that.orderForm.view12 = myData.transportPaymentMode;
                            that.orderForm.isTop = myData.isInsure == '2' ? true : false;
                        }
                    })
                    .catch(function (error) {
                        console.log(error);
                        that.loading = false;
                    });
            },
            getOrderDetailInfo(orderID, page) {
                let that = this;
                that.loading = true;
                //先清空
                var lenth = that.goodsList.length;
                that.goodsList.splice(0, lenth);
                getOrderDetailInfoPost(orderID, page)
                    .then(data => {
                        that.loading = false;
                        var myData = data.data;
                        if (myData.length > 0) {
                            //加入数据内容
                            for (let i of myData) {
                                var map = {
                                    id: i.id,
                                    hsCode: i.hsCode,
                                    hsName: i.hsName,
                                    specification: i.specification,
                                    isOwm: i.isOwm == '2' ? '是' : '否',
                                    amount: i.amount,
                                    statisticUnits: i.statisticUnits,
                                    unitPrice: i.unitPrice,
                                    totalPrice: i.totalPrice,
                                    originalGoodsPlace: i.originalGoodsPlace
                                };
                                if (that.goodsplace.length > 0) {
                                    var obj = {};
                                    obj = that.goodsplace.find(item => {
                                        return item.id === map.originalGoodsPlace; //筛选出匹配数据
                                    });
                                    if (obj != null) {
                                        map.originalGoodsPlace = obj.name;
                                    }
                                }
                                that.goodsList.push(map);
                            }
                            var page = data.page;
                            that.total = page.resultCount;
                            that.count = page.pageCount;
                            that.pageCurrent = page.pageCurrent;
                            that.size = 1000;
                        }
                    })
                    .catch(function (error) {
                        console.log(error);
                        that.loading = false;
                    });
            },
            handleHSSelect(value) {
                let that = this;
                var key = value.key.split('#');
                if(key[0]=='暂无数据'){
                    that.goodsForm.hsCode = '';
                    that.goodsForm.statisticUnits ='';
                    that.hsFlag = true;
                    return;
                }
                that.hsCode = key[0];

                that.goodsForm.hsCode = value.value;
                that.goodsForm.statisticUnits = key[1];
                that.hsFlag = true;

            },
            changeHS() {
                let that = this;
                if (that.hsFlag) {
                    that.hsCode = '';
                    that.hsFlag = false;
                }
            },
            //queryString 为在框中输入的值
            //callback 回调函数,将处理好的数据推回
            querySearchHSAsync(queryString, callback) {
                let that = this;
                that.list = [];
                //计算输入字符串长度
                var l = queryString.length;
                var blen = 0;
                var i = 0;
                for (i = 0; i < l; i++) {
                    if ((queryString.charCodeAt(i) & 0xff00) != 0) {
                        blen++;
                    }
                    blen++;
                }
                //从后台获取到对象数组
                if (blen >= 2) {
                    var str = queryString;
                    var type = 0;
                    if (parseFloat(str).toString() == 'NaN') {
                        type = 1;
                    }
                    getHSoptions(queryString, type)
                        .then(data => {
                            that.loading = false;
                            //在这里为这个数组中每一个对象加一个value字段, 因为autocomplete只识别value字段并在下拉列中显示
                            var myData = data.data;
                            if (myData.length > 0) {
                                for (let i of myData) {
                                    var map = {};
                                    map.value = i.hsName + '(' + i.hsCode + ')'; //将想要展示的数据作为value
                                    map.key = i.hsCode + '#' + i.specification + '';
                                    that.list.push(map);
                                }
                                callback(that.list);
                            }else{
                                var map = {};
                                map.value = '暂无数据'
                                map.key = '暂无数据'
                                that.list.push(map)
                                callback(that.list);
                                console.log(2222)
                            }
                        })
                        .catch(function (error) {
                            console.log(error);
                            that.loading = false;
                        });
                }
            },
            querySearchHSName(code) {
                let that = this;
                //从后台获取到对象数组
                getHSInfo(code)
                    .then(data => {
                        //在这里为这个数组中每一个对象加一个value字段, 因为autocomplete只识别value字段并在下拉列中显示
                        console.log('data = ', data);
                        var myData = data.data;
                        that.hsCode = myData.hsCode;
                        that.goodsForm.hsCode = myData.hsName + '(' + myData.hsCode + ')';
                        that.goodsForm.statisticUnits = myData.specification;
                        that.hsFlag = true;
                    })
                    .catch(function (error) {
                        console.log(error);
                    });
            },
            getCurrentDate(format) {
                var now = new Date();
                var year = now.getFullYear(); //得到年份
                var month = now.getMonth(); //得到月份
                var date = now.getDate(); //得到日期
                // var day = now.getDay();//得到周几
                var hour = now.getHours(); //得到小时
                var minu = now.getMinutes(); //得到分钟
                var sec = now.getSeconds(); //得到秒
                month = month + 1;
                if (month < 10) month = '0' + month;
                if (date < 10) date = '0' + date;
                if (hour < 10) hour = '0' + hour;
                if (minu < 10) minu = '0' + minu;
                if (sec < 10) sec = '0' + sec;
                var time = '';
                //精确到天
                if (format == 1) {
                    time = year + '-' + month + '-' + date;
                }
                //精确到分
                else if (format == 2) {
                    time =
                        year + '-' + month + '-' + date + ' ' + hour + ':' + minu + ':' + sec;
                }
                return time;
            },
            clearAll() {
                let that = this;
                that.orderForm.orderNum = '';
                that.orderForm.orderTime = that.getCurrentDate(1);
                that.orderForm.deliveryTime = that.getCurrentDate(1);
                that.orderForm.view1 = '';
                that.orderForm.view2 = '';
                that.orderForm.view3 = '';
                that.orderForm.view4 = '';
                that.orderForm.view5 = '';
                that.orderForm.view6 = '';
                that.orderForm.view7 = '';
                that.orderForm.view8 = '';
                that.orderForm.view9 = '';
                that.orderForm.view10 = '';
                that.orderForm.view11 = '';
                that.orderForm.isTop = false;
                var lenth = that.goodsList.length;
                that.goodsList.splice(0, lenth);
                that.goodsList.count = 0;
                that.goodsList.page = 1;
            }
        }
    };
</script>
<style rel='stylesheet/scss' lang='scss' scoped>
    @import 'src/styles/mixin.scss';

    .page-container {
        width: 100%;
    }
    @media (max-width: 1024px) {
        .page-container {
            width: 100%;

        }
    }
    @media (max-width: 1281px) {
        .page-container {
            width: 100%;

        }
    }

    .create-edit-post {
        padding: 20px;
    }

    .item-label {
        float: left;
        box-sizing: border-box;
        font-size: 14px;
        width: 70px;
        line-height: 80px;
    }

    .form-upload-img {
        margin-bottom: 20px;
    }

    .logo-item {
        float: left;
    }

    .editor-container {
        margin-bottom: 20px;
    }

    .normal-input {
        width: 100%;
    }

    .create-goods {
        margin-bottom: 10px;
    }

    .el-autocomplete {
        width: 100%;
    }

    .submit-btn {
        text-align: center;
        margin-top: 20px;

        .el-button {
            width: 200px;
        }
    }
</style>
